
$(function() {

	obj = $('[data-object]').attr('data-object');

	$('input:visible, select:visible').first().focus();
	
	$('.buttonset').buttonset();
	
	$('input[type="radio"]', '#visual-type').bind('click', function() {
		$('body').removeClass();
		$('body').addClass($(this).attr('id'));
		setCookie('app-style', $(this).attr('id'), 100);
	});
	
	
	$('[data-textsize]').live('click', function(e) {
		e.preventDefault();
		var size = parseInt($('body').css('fontSize'));
		if ($(this).attr('data-textsize') === 'plus')
			size += 1;
		else
			size -= 1;
		$('body').css('fontSize', size);
	});

	$('#add-image').live('click', function(e) {
		e.preventDefault();
		var newElement = $(".image-list li:last").clone();

		$('input', newElement).val('');

		newElement.appendTo(".image-list");
	});

	
        $( ".hasDatePicker" ).datepicker({'dateFormat': 'yy-mm-dd'});

/* Common
------------------------------------------------------------------------------------------ */
	
	// Seleccionar todos los checkbox
	$('[data-action="selectall"]').click(function() {
		checkboxes = $(this).parents('ul').find('input[type="checkbox"]');
		if ($(this).attr('checked'))
			checkboxes.attr('checked', 'checked');
		else
			checkboxes.removeAttr('checked');
	});
		
	if ($('#file-uploader').length) {
		createUploader();
	}
	
		if ($('#player')) {
		flowplayer("player", "/js/plugins/flowplayer/flowplayer-3.2.11.swf", {
			clip: {
				autoPlay: false
			}
		});
	}
		
});

function setCookie(name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toUTCString()+'; path=/');
}
/**
 * Crea un uploader para subir archivos adjuntos via Ajax
 */
function createUploader() {
	var uploader = new qq.FileUploader({
		// pass the dom node (ex. $(selector)[0] for jQuery users)
		element: document.getElementById('file-uploader'),
		onComplete: function(id, fileName, responseJSON){
			$('#main-form').append('<input type="hidden" name="data[Peliculas][video]" value="/uploads/videos/' + fileName + '"/>');
		},
		// path to server-side upload script
		action: '/admin/upload.php'
	});
}	




